<?php

namespace App\Service\Api;

use GuzzleHttp\Client;

class QrCodeService
{
    protected $client;

    public function readQRCode($imageUrl)
    {
        $url = 'https://api.uomg.com/api/qr.encode?url='.urlencode($imageUrl);

        try {
            // 在方法内部创建 Guzzle 客户端实例
            $client = new Client();
            $response = $client->get($url);
            $body = $response->getBody()->getContents();

            return json_decode($body, true);
        } catch (\Exception $e) {
            // 处理请求异常
            return [
                'error' => $e->getMessage()
            ];
        }
    }
}
